package org.ljx.taobao.controller;

import org.ljx.taobao.api.IShoppingService;
import org.ljx.taobao.api.entity.Shopping;
import org.ljx.taobao.service.ShoppingServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: Ljx
 * @Date: 2021/12/31 11:58
 * @role: 商品数量+1
 */
@WebServlet("/increase")
public class IncreaseServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;utf-8");
        IShoppingService iShoppingService = new ShoppingServiceImpl();
        int id = Integer.parseInt(req.getParameter("id"));
        Shopping shopping = new Shopping(id);
        boolean x = iShoppingService.increase(shopping);
        if (x) {
            resp.sendRedirect("query");
        } else {
            iShoppingService.delete(shopping);
            resp.sendRedirect("query");
        }

    }
}


